"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/10/28 13:32
@Description : 常用的模块

1. 随机数
2. 数学模块
"""
import random
import math
import  datetime
"""
for i in range(20):
    # [1,3]
    random_number = random.randint(1,3)
    print(random_number)
"""

# [0, 1)
random_number = random.random()
print(random_number)

# 列表数据  随机从列表中选取指定个数的数据
num_list = [1, 3, 5, 7, 9, 90, 86]
"""
new_list = list()
for num in range(3):
    index = random.randint(0, len(num_list) - 1)
    new_list.append(num_list[index])

print(new_list)
"""
#  随机选取数据  数据可能重复  放回选取
new_list = random.choices(num_list, k=3)
print(new_list)

#  不放回选取  选取的元素不重复
new_list = random.sample(new_list, k=3)
print(new_list)

print("-------------------math----------------------")
# 次幂
result = math.pow(2, 3)
print(result)
# 平方根
result = math.sqrt(4)
print(result)

# 向上取整  大于当前数字的最小整数
result = math.ceil(1.6)
print(result)
# 向下取整 小于当前数字的最大整数
result = math.floor(1.6)
print(result)

# 获取常量
PI = math.pi
print(PI)

print("-------------------datetime----------------------")
now = datetime.datetime.now()
print(now,type(now))

# 获取时间分量
year = now.year
print(f'year={year}')
month = now.month
print(f'month={month}')
day = now.day
print(f'day={day}')
hour = now.hour
print(f'hour={hour}')
minute = now.minute
print(f'minute={minute}')
second = now.second
print(f'second={second}')
weekday = now.weekday()
print(f'weekday={weekday}')
microsecond = now.microsecond
print(f'microsecond={microsecond}')

# 时间格式化输出
str_date = now.strftime('%Y/%m/%d %H:%M:%S')
print(f'str_date={str_date}')

# 时间字符串标识形式 转为datatime类型
str_time = '2025-10-28 13:32:50'
print(f'str_time={str_time},{type(str_time)}')
datetime_obj = datetime.datetime.strptime(str_time, '%Y-%m-%d %H:%M:%S')
print(f'datetime_obj={datetime_obj},type(datetime_obj)={type(datetime_obj)}')



